// 加载中指令
import loading from "@/assets/loading.svg"
import styles from "./loading.module.less";

function isExits(el){
    return el.querySelector("div[data-role=loading]")
}

function generateLoadingImg(){
    const div = document.createElement("div")
    const img = document.createElement("img");
   
    img.src = loading
    img.className = styles.loading
    div.appendChild(img)
    div.dataset.role = "loading";
    div.className = styles.back
    return div
}


export default (el,binging) =>{
    if(binging.value){
        if(!isExits(el)){
            const div = generateLoadingImg()
            el.appendChild(div)
        }
    } else {
        if(isExits(el)){
            isExits(el).remove()
        }
    }
}

